<style lang="scss">
	page{
		background: #FFFFFF;
		overflow-x: hidden;
		.all{
			width: 750upx;
			.logo{
				width: 344upx;
				height: 344upx;
				margin-top: 26upx;
				margin-left: 203upx;
			}
			.anniu{
				width: 670upx;
				height: 96upx;
				background: #A02731;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}
			.anniu_new{
				width: 670upx;
				height: 96upx;
				background: #C7CFCB;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}
			.agreement{
				display: flex;
				margin-top: 40upx;
				margin-left: 60upx;
				.agreement_image{
					width: 30upx;
					height: 30upx;
					margin-top: 3upx;
				}
				.agreement_text{
					margin-left: 30upx;
					height: 36upx;
					font-size: 26upx;
					font-weight: 400;
					color: #999999;
					line-height: 36upx;
				}
			}
			.all_bj{
				width: 520upx;
				height: 388upx;
				position: fixed;
				bottom: 0;
				margin-left: 115upx;
			}
			.new{
				width: 700upx;
				padding: 0;
				margin-left: 25upx;
			}
			.new_box{
				width: 700upx;
				padding: 14upx 0;
				border-bottom: 1upx solid #DDDDDD;
				display: flex;
			}
			.new_box_image{
				width: 52upx;
				height: 54upx;
			}
			.new_box_input{
				margin-left: 8upx;
				margin-top: 8upx;
				width: 478upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #222222;
				line-height: 40upx;
			}
			.new_box_text{
				width: 140upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #6B542A;
				line-height: 40upx;
			}
			.zhuche{
				text-align: center;
				font-size: 28upx;
				color: #007AFF;
				padding: 20upx 0;
				width: 100%;
			}
		}
	}
</style>
<template>
	<view class="all">
		<image class="logo" src="../../../static/logo.png"></image>
		<view class="new">
			<view class="new_box" style="margin-top: 20upx;">
				<!-- <image class="new_box_image" src="../../../static/66.png"></image> -->
				<input placeholder="请输入账号" @input="account_input" class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<!-- <image class="new_box_image" src="../../../static/65.png"></image> -->
				<input placeholder="请输入手机号" @input="phone_input" type="number" maxlength="11" class="new_box_input" />
				<view class="new_box_text" v-if="showText_now==true" @click.stop="code_tap">获取验证码</view>
				<view v-if="showText_now!=true" class="new_box_text" style="text-align: right;">{{second_now}}s</view>
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<!-- <image class="new_box_image" src="../../../static/66.png"></image> -->
				<input placeholder="请输入验证码" @input="code_input" type="number" maxlength="6" class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<!-- <image class="new_box_image" src="../../../static/72.png"></image> -->
				<input placeholder="请输入新密码" @input="password_input" password class="new_box_input" />
			</view>
		</view>
		<button :class="is_key == ''?'anniu_new':'anniu'"  @tap="getUserInfo">修改</button>
		<view class="agreement">
			<image class="agreement_image" @click="dianji" :src="is_dianji==0?'../../../static/48.png':'../../../static/67.png'"></image>
			<view class="agreement_text" @click="dianji"> 我已同意 <text style="color: #393E42;" @click.stop="Service_tap">《用户协议》</text> 和 <text style="color: #393E42;" @click.stop="Privacy_tap">《隐私协议》</text> </view>
		</view>
	</view>
</template>
<script>
	import urlConfig from 'common/config.js';
	export default {
		data() {
			return {
				is_dianji:0,
				token:'',
				phone:'',
				code:'',
				codes:'',
				account:'',
				showText_now:true,
				is_key:'',
				second_now:60,
				password_data:'',
				code_xcx:''
			}
		},
		onLoad(num) {
			// var str = window.location.href + ''
			// if(num.token) {
			// 	this.token = num.token
			// }else{
			// 	var string= str
			// 	var before = string.split('=')
			// 	var aa = before[1] + ''
			// 	if(str.indexOf("token") !== -1){
			// 		var stringa= aa
			// 		var beforea = aa.split('#')[0]
			// 		var aftera = aa.split('#')[1]
			// 		console.log('beforea',beforea)
			// 		this.token = beforea
			// 	}
			// }
			// uni.setStorageSync('is_token', '1');
		},
		onShow() {
			// this.login_tap()
		},
		methods: {
			login_tap() {
				var that = this
				that.wanglemima()
				// uni.login({
				// 	provider: 'weixin',
				// 	success: (loginRes) => {
				// 		that.code_xcx = loginRes.code
				// 		// that.loginTest(that.code)
				// 	}
				// })
			},
			Forgot_tap() {
				uni.navigateTo({
					url:'../Forgot_tap/Forgot_tap'
				})
			},
			disembark() {
				uni.navigateTo({
					url:'../disembark/disembark'
				})
			},
			dianji() {
				if( this.is_dianji == 0 ) {
					this.is_dianji = 1
				}else{
					this.is_dianji = 0
				}
			},
			//获取验证码
			code_tap() {
				if( this.phone != '' && this.phone.length == 11 ) {
					this.showText_now = false
					this.acquire_api(this.phone) //获取验证码
					var interval = setInterval(() => {
					    let times = --this.second_now
					    this.second_now = times<10?'0'+times:times //小于10秒补 0
					}, 1000)
					setTimeout(() => {
					    clearInterval(interval)
					    this.second_now=60
					    this.showText_now = true
					}, 60000)
				}else{
					uni.showToast({
						title: '请输入正确手机号',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			acquire_api(phone) {
				var that = this
				uni.request({
					url: urlConfig.Url + 'sms/sms',
					data:{
						access_token:uni.getStorageSync('access_token'),
						phone:this.phone
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.data.code == 0) {
						}else {
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					}
				});
			},
			phone_input(num) {
				this.phone = num.detail.value
				this.panduan()
			},
			codes_input(num) {
				this.codes = num.detail.value
			},
			account_input(num) {
				this.account = num.detail.value
				this.panduan()
			},
			panduan() {
				if(this.phone.length == 11 && this.code.length >= 4  && this.account != '' && this.password_data != '' ) {
					this.is_key = 1
				}
			},
			password_input(num) {
				this.password_data = num.detail.value
				this.panduan()
			},
			code_input(num) {
				this.code = num.detail.value
				this.panduan()
			},
			Service_tap() {
				uni.navigateTo({
					url: '/pages/about/about'
				})
			},
			Privacy_tap() {
				uni.navigateTo({
					url: '/pages/guide/guide'
				})
			},
			getUserInfo() {
				var that = this
				if( that.phone.length == 11 ) {
					if( that.password_data != '' ) {
						if( that.is_dianji == 1 ) {
							if(that.account != '') {
								that.login_tap()
							}else{
								uni.showToast({
									title: '请输入账号',
									duration: 2000,
									icon: 'none'
								});
							}
						}else{
							uni.showToast({
								title: '请勾选协议',
								duration: 2000,
								icon: 'none'
							});
						}
					}else{
						uni.showToast({
							title: '请输入密码',
							duration: 2000,
							icon: 'none'
						});
					}
				}else{
					uni.showToast({
						title: '手机号错误',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			wanglemima() {
				var that = this
				uni.request({
					url: urlConfig.Url + 'login/forget',
					data:{
						account:that.account,
						code:that.code,
						phone:that.phone,
						password:that.password_data
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						console.log('----11')
						if (res.data.code == 0) {
							uni.removeStorageSync('access_token');
							uni.removeStorageSync('is_token');
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
							setTimeout(function () {
							    uni.reLaunch({
							    	url:'../disembark/disembark'
							    })
							}, 2000);
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					},
					fail(ddd) {
						console.log('ddd',ddd)
						uni.showModal({
							title: '失败',
							content: ddd,
							cancelText:'返回',
							confirmColor:'#A02731',
							success: function (res) {
								if (res.confirm) {
									console.log('用户点击确定');
									
								} else if (res.cancel) {
									
								}
							}
						});
					}
				});
			},
		}
	}
</script>
















